package com.example.bingobox.model;

import java.util.ArrayList;
import java.util.List;

public class Task {
    private String id;
    private String name;
    private String description;
    private long deadline;
    private String type;
    private boolean completed;
    private List<TimeLabel> timeLabels = new ArrayList<>();
    private String cityType;
    private long completeTime;
    private boolean favorite;
    private transient boolean selected;
    private boolean isHometown;
    private boolean isResidence;

    public String getId() { return id; }
    public void setId(String id) { this.id = id; }
    
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    
    public long getDeadline() { return deadline; }
    public void setDeadline(long deadline) { this.deadline = deadline; }
    
    public String getType() { return type; }
    public void setType(String type) { this.type = type; }
    
    public boolean isCompleted() { return completed; }
    public void setCompleted(boolean completed) {
        this.completed = completed;
        if (completed) {
            this.completeTime = System.currentTimeMillis();
        } else {
            this.completeTime = 0; // 当任务未完成时，重置完成时间
        }
    }

    public String getCityType() {
        return cityType;
    }

    public void setCityType(String cityType) {
        this.cityType = cityType;
    }

    public long getCompleteTime() {
        return completeTime;
    }

    public void setCompleteTime(long completeTime) {
        this.completeTime = completeTime;
    }

    public boolean isFavorite() {
        return favorite;
    }

    public void setFavorite(boolean favorite) {
        this.favorite = favorite;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }

    public boolean isHometown() {
        return isHometown;
    }

    public void setHometown(boolean hometown) {
        isHometown = hometown;
    }

    public boolean isResidence() {
        return isResidence;
    }

    public void setResidence(boolean residence) {
        isResidence = residence;
    }

    public String getCityTypeText() {
        if (isHometown && isResidence) {
            return "大本营";
        } else if (isHometown) {
            return "老家";
        } else if (isResidence) {
            return "常住城市";
        } else {
            return "旅游出差";
        }
    }

    public static class TimeLabel {
        private String dayType;
        private boolean allDay;
        private int startHour;
        private int startMinute;
        private int endHour;
        private int endMinute;

        public TimeLabel() {}

        public TimeLabel(String dayType) {
            this.dayType = dayType;
        }

        public TimeLabel(String dayType, int startHour, int startMinute, int endHour, int endMinute) {
            this.dayType = dayType;
            this.startHour = startHour;
            this.startMinute = startMinute;
            this.endHour = endHour;
            this.endMinute = endMinute;
        }

        public boolean isAllDay() {
            return startHour == -1 || endHour == -1;
        }

        public String getTimeRangeText() {
            if (isAllDay()) {
                return "全天";
            }
            return String.format("%02d:%02d-%02d:%02d", 
                startHour, startMinute, endHour, endMinute);
        }

        // Getters and setters
        public String getDayType() { return dayType; }
        public void setDayType(String dayType) { this.dayType = dayType; }
        public Integer getStartHour() { return startHour; }
        public void setStartHour(Integer startHour) { this.startHour = startHour; }
        public Integer getStartMinute() { return startMinute; }
        public void setStartMinute(Integer startMinute) { this.startMinute = startMinute; }
        public Integer getEndHour() { return endHour; }
        public void setEndHour(Integer endHour) { this.endHour = endHour; }
        public Integer getEndMinute() { return endMinute; }
        public void setEndMinute(Integer endMinute) { this.endMinute = endMinute; }
        public void setAllDay(boolean allDay) {
            this.allDay = allDay;
        }
    }

    // Getter and setter for timeLabels
    public List<TimeLabel> getTimeLabels() { return timeLabels; }
    public void setTimeLabels(List<TimeLabel> timeLabels) { this.timeLabels = timeLabels; }
} 